package com.wjw.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.wjw.common.controller.SuperController;
import com.wjw.entity.Admin;
import com.wjw.service.IAdminService;

@Controller
public class AdminController  extends SuperController{
	
	    @Resource  
	    private IAdminService adminService;  
	    
		/**
		 * 登录页面
		 * @throws UnsupportedEncodingException 
		 */
	
		@RequestMapping(value={"","/","/index"})
		public String login(String return_url,Model model) throws UnsupportedEncodingException{
			String index = "/index";
			model.addAttribute("return_url", StringUtils.isNotBlank(return_url)?URLDecoder.decode(return_url,"UTF-8"):index);
			return "login";
		}
	    
		/**
		 * 执行登录
		 */
	 
		@RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
		public String adminLogin(String adminName,String adminPassword,Model model) {
			if(StringUtils.isBlank(adminName)){
				model.addAttribute("msg", "用户名不能为空");
				return "login";
			}
			if(StringUtils.isBlank(adminPassword)){
				model.addAttribute("msg", "密码不能为空");
				return "login";
			}
			Admin  admin = adminService.login(adminName,adminPassword);
			if(admin==null){
				model.addAttribute("msg", "用户名或密码错误");
				return "login";
		}
			return "adminIndex";
	
   }
		
   
}